class CatalogController < ApplicationController
  before_filter :initialize_cart
  def index
    @page_title = t :listing_books
    @books = Book.paginate(:page => params[:page],
      :order => "books.id desc",
      :include => [:authors, :publisher], :per_page => 10)
  end
  def show
    @book = Book.find(params[:id]) rescue nil
    return render(:text => t(:not_found), :status => 404) unless @book
    @page_title = @book.title
  end
  def search
    @page_title = t :search
    if params[:commit] == "Search" || params[:q]
      @books = Book.paginate_search(params[:q].to_s.upcase, :page => params[:page], :per_page => 10)
      unless @books.size > 0
        flash.now[:notice] = t :no_books_found_matching_your_criteria
      end
    end
  end
  def latest
    @page_title = t :latest_books
    @books = Book.latest
  end
end
